<?php

namespace App\Home\Requests;

use App\Admin\Models\SystemModel;
use App\Home\Models\Demo;
use Illuminate\Support\Arr;

class DemoRequest extends FormRequest
{
public $validationRules = <<< EOF
{
    "input": "nullable|max:50",
    "dynamic_input": "nullable|max:65535",
    "textarea": "nullable|max:65535",
    "dynamic_textarea": "nullable|max:65535",
    "single_file": "nullable|max:500",
    "multiple_file": "nullable|max:65535",
    "single_box": "nullable|max:255",
    "multiple_box": "nullable|max:500",
    "single_select": "nullable|max:255",
    "multiple_select": "nullable|max:500",
    "transfer": "nullable|max:500",
    "select_tree": "nullable|max:255",
    "cascader": "nullable|max:255",
    "editor": "nullable|max:65535",
    "date": "nullable|date",
    "time": "nullable|max:5",
    "datetime": "nullable|date",
    "password": "nullable|max:255",
    "other": "nullable|max:50"
}
EOF;   

    public function rules()
    {
        $rules = json_decode($this->validationRules, true);
        $keys = $this->keys();
        if ($this->isMethod('get')) {
            $rules = Arr::only($rules, []);
        }
        if ($this->isMethod('post')) {
            $rules = $this->makeRules('demo', $rules);
        }
        if ($this->isMethod('put')) {
            $rules = $this->makeRules('demo', Arr::only($rules, $keys));
        }
        
        return $rules;
    }

    public function messages()
    {
        return [];
    }

    public function attributes()
    {
        $systemModel = app(SystemModel::class);
        $demo = app(Demo::class);
        return $systemModel->fieldAttributes($demo->getTable());
    }
}
